package com.example.topnewsdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.example.topnewsdemo.NewsAdapter;
import com.example.topnewsdemo.NewsBean;
import com.example.topnewsdemo.R;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private String[] titles = {"各地餐企齐行动，杜绝餐饮浪费",
            "………………………标题……………………………",
            "………………………标题……………………………",
            "………………………标题……………………………",
            "………………………标题……………………………",
            "………………………标题……………………………"
    };
    private String[] names={"央视新闻客户端","……用户名……","……用户名……","……用户名……","……用户名……","……用户名……"};
    private  String[] comments={"9880评","评论数据","评论数据","评论数据","评论数据","评论数据"};
    private  String[] times={"5小时前","发布时间","发布时间","发布时间","发布时间","发布时间"};
    private int[] icons1 = {R.drawable.food,R.drawable.takeout,R.drawable.e_sports};
    private int[] icons2 = {R.drawable.sleep1,R.drawable.sleep2,R.drawable.sleep3,
            R.drawable.fruit1,R.drawable.fruit2,R.drawable.fruit3};
    private int[] types = {1,1,2,1,2,1};
    private RecyclerView mRecyclerView;
    private NewsAdapter mAdapter;
    private List<NewsBean> NewsList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setDate();
        mRecyclerView = findViewById(R.id.rv_list);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new NewsAdapter(com.example.topnewsdemo.MainActivity.this,NewsList);
        mRecyclerView.setAdapter(mAdapter);
    }
    private void setDate(){
        NewsList = new ArrayList<NewsBean>();
        NewsBean bean;
        for (int i = 0;i < titles.length; i++){
            bean = new NewsBean();
            bean.setId(i + 1);
            bean.setTitle(titles[i]);
            bean.setName(names[i]);
            bean.setCommet(comments[i]);
            bean.setTime(times[i]);
            bean.setType(types[i]);
            switch (i) {
                case 0:
                    List<Integer> imgList0 = new ArrayList<>();
                    bean.setImgList(imgList0);
                    break;
                case 1:
                    List<Integer> imgList1 = new ArrayList<>();
                    imgList1.add(icons1[i - 1]);
                    bean.setImgList(imgList1);
                    break;
                case 2:
                    List<Integer> imgList2 = new ArrayList<>();
                    imgList2.add(icons2[i - 2]);
                    imgList2.add(icons2[i - 1]);
                    imgList2.add(icons2[i]);
                    bean.setImgList(imgList2);
                    break;
                case 3:
                    List<Integer> imgList3 = new ArrayList<>();
                    imgList3.add(icons1[i - 2]);
                    bean.setImgList(imgList3);
                    break;
                case 4:
                    List<Integer> imgList4 = new ArrayList<>();
                    imgList4.add(icons2[i - 1]);
                    imgList4.add(icons2[i]);
                    imgList4.add(icons2[i + 1]);
                    bean.setImgList(imgList4);
                    break;
                case 5:
                    List<Integer> imgList5 = new ArrayList<>();
                    imgList5.add(icons1[i - 3]);
                    bean.setImgList(imgList5);
                    break;
            }
            NewsList.add(bean);
        }
    }
}